﻿/*
 * Author: Duncan Jenkins
 * 
 * Description: Base class for a "Mean" - It contains it's own Red, Green and Blue values, a list of associated pixels
 *              and a list of all Red, Green and Blue values added together. Also contains a label. Capability of 
 *              associating a pixel, and for calculating the mean.
 * */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LibraryCS {
    public class Mean {
        public int Red, Green, Blue;
        public int Reds, Greens, Blues;
        public List<int> pixels = new List<int>();
        public int Label;

        public Mean(int r, int g, int b, int l) {
            Red = r;
            Green = g;
            Blue = b;
            Label = l;
        }

        public void addPixel(int index, int r, int g, int b) {
            pixels.Add(index);
            Reds += r;
            Greens += g;
            Blues += b;
        }

        public bool calculateMean() {
            if (pixels.Count != 0) {
                int oldRed = Red;
                int oldGreen = Green;
                int oldBlue = Blue;
                Red = (int)(Reds / pixels.Count);
                Green = (int)(Greens / pixels.Count);
                Blue = (int)(Blues / pixels.Count);

                if (Math.Abs(oldRed - Red) == 0 && Math.Abs(oldGreen - Green) == 0 && Math.Abs(oldBlue - Blue) == 0) {
                    return true;
                }
            }

            return false;
        }
    }
}
